

cd "C:\Users\junya\Dropbox\Academic\Research\Anticorruption and Selection (Shao and Zhang)\Draft\BJPS Final Files\Replication Files"
use data_province_panel, clear
************ First Stage  ****************

xtset prov year

**************************************************************************** 
************ Figure 2: Export for Plotting IV Validity *********************
****************************************************************************

foreach i of varlist disciplined_1  disciplined_4_m  gdp total_pop graduate pri_output wage_gov  wage_urban_average emp_gov emp_allurban {
reg `i' i.year##xi if year>=2008 & year<=2015 
margins year, over(xi) noestimcheck
expmat exr_`i'
}



********************************************************************************************
***************** Table A.4: Public Attention and Anticorruption Enforcement ***************
********************************************************************************************
eststo clear
eststo m1: reg  fanfu  i.year disciplined_1 if year>=2008 & year<=2015 , robust cluster(prov)
estadd local yf "\(\checkmark\)"

eststo m2: reg  fanfu  i.year i.prov  disciplined_1 if year>=2008 & year<=2015 , robust cluster(prov)
estadd local pf "\(\checkmark\)"
estadd local yf "\(\checkmark\)"

eststo m3: reg  fanfu  i.year i.prov   gdp total_pop disciplined_1 if year>=2008 & year<=2015 , robust cluster(prov)
estadd local pf "\(\checkmark\)"
estadd local yf "\(\checkmark\)"




esttab m*  using out1.txt, nonote nobaselevels keep(disciplined_1 gdp total_pop) ///
order(disciplined_1 gdp total_pop ) b(3) se(3) ///
star(+ 0.1 * 0.05 ** 0.01) label booktabs replace   ///
nomtitles mgroup(`"Baidu index for "anticorruption" "', pattern(1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(yf pf r2_a N, labels("Year fixed effects" "Province fixed effects"    "Adjusted R\(^2\)" "Observations") fmt(0 0 2 0) )


**************************************************************************
******************** Table A.5: First-stage results **********************
**************************************************************************
eststo clear

eststo m2: reg disciplined_1  i.prov  year  xipost post if year>=2004 & year<=2015 
test xipost post
estadd scalar f=`r(F)'
estadd local pf "\(\checkmark\)"

eststo m3: reg disciplined_1 i.prov year  gdp expenditure total_pop priscale xipost post if year>=2004 & year<=2015 
test xipost post
estadd scalar f=`r(F)'
estadd local pf "\(\checkmark\)"

eststo m4: reg disciplined_4_m i.prov  year  xipost post if year>=2004 & year<=2015  
test xipost post
estadd scalar f=`r(F)'
estadd local pf "\(\checkmark\)"

eststo m5: reg disciplined_4_m i.prov  year gdp expenditure total_pop priscale  xipost post if year>=2004 & year<=2015  
test xipost post
estadd scalar f=`r(F)'
estadd local pf "\(\checkmark\)"

esttab m*  using out1.txt, nonote nobaselevels keep(post xipost  gdp expenditure total_pop priscale year) ///
order(post xipost  year gdp expenditure total_pop priscale ) b(3) se(3) ///
star(+ 0.1 * 0.05 ** 0.01) label booktabs replace   ///
nomtitles mgroup("Anticorruption enforcement (major cases)" "Anticorruption enforcement (all cases)", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(pf f N, labels("Province fixed effects" "First stage F" "Observations") fmt(0 2 0) )


***************************************************************************************
******************** Table A.6: Results on exclusion restriction **********************
***************************************************************************************

eststo clear
eststo m1: reg  gdp i.prov  year  xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"


eststo m2: reg  total_pop i.prov  year  xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"


eststo m3: reg  graduate i.prov  year  loggdp xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"

eststo m4: reg  pri_output i.prov  year  loggdp xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"

eststo m5: reg  wage_gov i.prov  year loggdp xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"

eststo m6: reg  wage_urban_average i.prov  year loggdp  xipost post  if year>=2008 & year<=2015, robust
test xipost post 
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"

eststo m7: reg  emp_gov i.prov  year  loggdp xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"

eststo m8: reg  emp_allurban i.prov  year  loggdp xipost post  if year>=2008 & year<=2015, robust
test xipost post
estadd scalar f=`r(p)'
estadd local pf "\(\checkmark\)"

esttab m*  using out1.txt, nonote nobaselevels keep(post xipost) ///
order(post xipost) b(3) se(3) ///
star(* 0.1 ** 0.05 *** 0.01) label booktabs replace   ///
nomtitles mgroup("GDP" "Population" "\# of college graduates" "Total private sector output" "Wage: government job" "Wage: urban average" "Total government employment" "Total urban employment", pattern(1 1 1 1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(f pf  N, labels("F test of joint significance (\(p\) value)" "Province and year fixed effects"  "Observations") fmt(2 0 0) )
 









****************************************************************************************************************
***************** Table A.13: Enforcement on Public Perception and Civil Service Job Application ***************
****************************************************************************************************************


eststo clear

// Perception of Benefits //
eststo m1: ivreg2  F.change year (disciplined_1 = post xipost),robust
estadd scalar f=`e(cdf)'


eststo m2: ivreg2  F.change i.prov year gdppc total_pop  expenditure priscale  (disciplined_1 = post xipost),robust  
estadd scalar f=`e(cdf)'
estadd local pf "\(\checkmark\)"


// Number of Applicants //
eststo m3: ivreg2  apply_k i.prov   year    (disciplined_1 = post xipost)  if year>=2006 ,robust 
estadd scalar f=`e(cdf)'
 
eststo m4: ivreg2  apply_k i.prov year gdppc total_pop expenditure priscale  (disciplined_1 = post xipost) if year>=2006  ,robust  cluster(prov)
estadd scalar f=`e(cdf)'
estadd local pf "\(\checkmark\)"



esttab m*  using out1.txt, nonote nobaselevels keep(disciplined_1 gdppc total_pop  expenditure priscale   year) ///
order(disciplined_1 gdppc total_pop expenditure priscale year) b(3) se(3) ///
star(+ 0.1 * 0.05 ** 0.01) label booktabs replace   ///
mtitles("IV" "IV" "IV" "IV") mgroup("\% change in public perception of benefits from government jobs" "\# of civil service applicants (in 10,000)", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats(pf f N, labels("Province fixed effects" "First stage F" "Observations") fmt(0 2 0) )
